<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Order
{
    public function orderList()
    {
//        $post  = Request::param();
        $post = Request::get();

        $where = [];
        if (isset($post['keywords']) && !empty($post['keywords'])) $where[] = ['o.order_sn', 'like', "%{$post['keywords']}%"];
        if (isset($post['status']) && !empty($post['status'])) $where[] = ['o.status', 'like', "{$post['status']}"];
        if (isset($post['start_time']) && !empty($post['start_time'])) $where[] = ['o.addtime', '>=', strtotime($post['start_time'])];
        if (isset($post['end_time']) && !empty($post['end_time'])) $where[] = ['o.addtime', '<=', strtotime($post['end_time'])];
        if (isset($post['min_price']) && !empty($post['min_price'])) $where[] = ['o.price', '>=', $post['min_price']];
        if (isset($post['max_price']) && !empty($post['max_price'])) $where[] = ['o.price', '<=', $post['max_price']];
        if (isset($post['order_status'])) $where[] = ['status', 'in', $post['order_status']];

        View::assign($post);
        unset($post['order']);
        $arr = Db::name("order_status")->select();

        $list = Db::name('order')
            ->alias('o')
            ->join('user u', 'o.uid = u.id')
            ->join('order_status os', 'o.status = os.status_id')
            ->where($where)
            ->field('o.*')
            ->field('u.uname')
            ->field('os.order_status')
            ->paginate([
                'list_rows' => 4,
                'query' => $post
            ]);
        View::assign('list', $list);
        View::assign('arr', $arr);

        $status = Db::name('order_status')->field(true)->select();
        View::assign('status', $status);

        return view();
    }

    public function orderDetail()
    {
        return view();
    }

}
